# Load packages
require(tidyverse)
require(flowCore)
require(ggcyto)
# Load data
fs <- read.flowSet(path = here::here("flow/data"),
alter.names = TRUE)
# Structure of flowSet data
str(fs)
Formal class 'flowSet' [package "flowCore"] with 2 slots
..@ frames :<environment: 0x7f940b1f3e50>
..@ phenoData:Formal class 'AnnotatedDataFrame' [package "Biobase"] with 4 slots
.. .. ..@ varMetadata :'data.frame': 1 obs. of 1 variable:
.. .. .. ..$ labelDescription: chr "Name"
.. .. ..@ data :'data.frame': 3 obs. of 1 variable:
.. .. .. ..$ name: 'AsIs' chr [1:3] "S2_27SEP2022.fcs" "S3_27SEP2022.fcs" "S4_27SEP2022.fcs"
.. .. ..@ dimLabels : chr [1:2] "rowNames" "columnNames"
.. .. ..@ .__classVersion__:Formal class 'Versions' [package "Biobase"] with 1 slot
.. .. .. .. ..@ .Data:List of 1
.. .. .. .. .. ..$ : int [1:3] 1 1 0
.. .. .. .. ..$ names: chr "AnnotatedDataFrame"
# Specific sample data
fs@frames$S2_27SEP2022.fcs
flowFrame object 'S2_27SEP2022.fcs'
with 130945 cells and 16 observables:
name desc range minRange maxRange
$P1 HDR.T HDR-T 262144 0 262143
$P2 FSC.A FSC-A 262144 0 262143
$P3 FSC.H FSC-H 262144 0 262143
$P4 FSC.W FSC-W 262144 0 262143
$P5 SSC.A SSC-A 262144 -111 262143
... ... ... ... ... ...
$P12 Y2.H dsRed/txRed-H 262144 -26.1335 262143
$P13 Y2.W dsRed/txRed-W 262144 0.0000 262143
$P14 B2.A PI/LSS-mKate-A 262144 -111.0000 262143
$P15 B2.H PI/LSS-mKate-H 262144 -69.7272 262143
$P16 B2.W PI/LSS-mKate-W 262144 0.0000 262143
155 keywords are stored in the 'description' slot
autoplot(fs[[1]])
autoplot(fs[[2]])
autoplot(fs[[3]])
ggcyto(fs,
aes(x = B2.A)) +
geom_density() +
facet_wrap(~ name,
ncol = 1) +
ggcyto_par_set(limits = "instrument")
ggcyto(fs,
aes(x = SSC.A)) +
geom_density() +
facet_wrap(~ name,
ncol = 1) +
ggcyto_par_set(limits = "instrument")
ggcyto(fs,
aes(x = B2.A)) +
geom_density() +
scale_x_logicle() +
facet_wrap(~ name,
ncol = 1) +
ggcyto_par_set(limits = "instrument")
ggcyto(fs,
aes(x = SSC.A)) +
scale_x_logicle() +
geom_density() +
facet_wrap(~ name,
ncol = 1) +
ggcyto_par_set(limits = "instrument")
FSC – relative size
SSC – relative granularity
ggcyto(fs,
aes(y = SSC.A,
x = FSC.A)) +
geom_hex(bins = 200) +
facet_wrap(~ name,
ncol = 1) +
ggcyto_par_set(limits = "instrument")
ggcyto(fs[[1]],
aes(x = B2.A,
y = SSC.A)) +
geom_hex(bins = 200) +
ggcyto_par_set(limits = "instrument")
ggcyto(fs[[2]],
aes(x = B2.A,
y = SSC.A)) +
geom_hex(bins = 200) +
ggcyto_par_set(limits = "instrument")
ggcyto(fs[[3]],
aes(x = B2.A,
y = SSC.A)) +
geom_hex(bins = 200) +
ggcyto_par_set(limits = "instrument")
ggcyto(fs[[1]],
aes(x = B2.A,
y = SSC.A)) +
geom_hex(bins = 200) +
scale_x_logicle() +
scale_y_logicle() +
ggcyto_par_set(limits = "instrument")
ggcyto(fs[[1]],
aes(x = B2.A,
y = SSC.A)) +
geom_hex(bins = 200) +
scale_x_flowCore_fasinh() +
scale_y_flowCore_fasinh() +
ggcyto_par_set(limits = "instrument")
# Create gating set object
gs <- GatingSet(fs)
# Create gate -----
# 7-AAD and SSC cut off
gate_7aad_ssc <- rectangleGate(filterId = "7-AAD High & Low SSC",
"B2.A" = c(25000, Inf),
"SSC.A" = c(0, 1e4))
# Large gate
gate_7aad <- rectangleGate(filterId = "7-AAD High",
"B2.A" = c(25000, Inf))
# Add gate to dat
gs_pop_add(gs, gate_7aad_ssc)
[1] 2
gs_pop_add(gs, gate_7aad)
[1] 3
# Recompute
recompute(gs)
# Plot
ggcyto(fs[[2]],
aes(x = B2.A,
y = SSC.A),
subset = "root") +
geom_hex(bins = 200) +
geom_gate(gate_7aad_ssc) +
ggcyto_par_set(limits = "instrument")
ggcyto(fs[[2]],
aes(x = B2.A,
y = SSC.A),
subset = "root") +
geom_hex(bins = 200) +
geom_gate(gate_7aad) +
ggcyto_par_set(limits = "instrument")
# Plot
ggcyto(fs[[3]],
aes(x = B2.A,
y = SSC.A),
subset = "root") +
geom_hex(bins = 200) +
geom_gate(gate_7aad_ssc) +
ggcyto_par_set(limits = "instrument")
ggcyto(fs[[3]],
aes(x = B2.A,
y = SSC.A),
subset = "root") +
geom_hex(bins = 200) +
geom_gate(gate_7aad) +
ggcyto_par_set(limits = "instrument")
# Count stuff
ps <- gs_pop_get_count_with_meta(gs)
# Details of count
ps %>%
mutate(percent_of_parent = (Count/ParentCount)*100,
nuclei_conc = Count/50,
name = str_remove_all(name, "_27SEP2022.fcs")) %>%
select(name, Count, ParentCount, Population,
percent_of_parent, nuclei_conc)
name Count ParentCount Population percent_of_parent nuclei_conc
1: S2 46976 130945 /7-AAD High & Low SSC 35.87460 939.52
2: S2 70799 130945 /7-AAD High 54.06774 1415.98
3: S3 73309 158915 /7-AAD High & Low SSC 46.13095 1466.18
4: S3 122374 158915 /7-AAD High 77.00595 2447.48
5: S4 22497 51359 /7-AAD High & Low SSC 43.80342 449.94
6: S4 37471 51359 /7-AAD High 72.95898 749.42
ggcyto(fs[[1]],
aes(x = B2.A),
subset = "7-AAD High & Low SSC") +
geom_density() +
scale_x_logicle() +
ggcyto_par_set(limits = "instrument")
ggcyto(fs[[2]],
aes(x = B2.A),
subset = "7-AAD High & Low SSC") +
geom_density() +
scale_x_logicle() +
ggcyto_par_set(limits = "instrument")
ggcyto(fs[[3]],
aes(x = B2.A),
subset = "7-AAD High & Low SSC") +
geom_density() +
scale_x_logicle() +
ggcyto_par_set(limits = "instrument")